package shuiguo.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import shuiguo.bean.XiaoShouBean;
import util.JDBCUtils;

public class XiaoShouDao {
	Connection con=null;
	PreparedStatement  ps=null;
	public int insert(XiaoShouBean xiao) {
		String sql="insert into s_xiaoshou(shuiguoname,sex,number,danjia,xiaoshoumoney"+
	",xiaoshoutime)values(?,?,?,?,?,?)";
		try {
			con=JDBCUtils.getConnection();
			ps=con.prepareStatement(sql);
			ps.setString(1, xiao.getShuiGuoName());
			ps.setInt(2, xiao.getSex());
			ps.setInt(3, xiao.getNumber());
			ps.setBigDecimal(4, xiao.getDanJia());
			ps.setBigDecimal(5, xiao.getXiaoShouMoney());
			ps.setString(6, xiao.getXiaoShouTime());
			return ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	public List<XiaoShouBean> selectAll(){
		String sql="select * from s_xiaoshou";
		ResultSet rs= null;
		List<XiaoShouBean> list=new ArrayList<>();
		try {
			con=JDBCUtils.getConnection();
			ps=con.prepareStatement(sql);
			rs=ps.executeQuery();
			while(rs.next()) {
				XiaoShouBean xiao=new XiaoShouBean();
				xiao.setDanJia(rs.getBigDecimal("danjia"));
				xiao.setNumber(rs.getInt("number"));
				xiao.setSex(rs.getInt("sex"));
				xiao.setShuiGuoName(rs.getString("shuiguoname"));
				xiao.setXiaoShouMoney(rs.getBigDecimal("xiaoshoumoney"));
				xiao.setXiaoShouTime(rs.getString("xiaoshoutime"));
				list.add(xiao);
			}
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
